import { defineStore } from 'pinia'

import { lang } from '~locales'
import { PREFIX } from '~utils/util'

const useThemeStore = defineStore('theme', {
  state: () => ({
    theme: {
      language: lang,
      size: 'default',
      autoInsertSpace: false,
      mode: false,
      skin: ''
    }
  }),
  actions: {
    setTheme(theme) {
      this.theme = {
        ...this.theme,
        ...theme
      }
    }
  },
  persist: {
    key: `${PREFIX}|theme`,
    storage: window.sessionStorage,
    paths: ['theme']
  }
})

export default useThemeStore
